<template>
    <div class="demo">
        <h3>学生名称:{{name}}</h3>
        <h3>学生年龄:{{age}}</h3>
        <button @click="sendNameToApp">发送学校名称</button>
        <button @click="sendNameToApp2">第二个自定义事件</button>
        <button @click="unbind">解绑自定义事件</button>
        <button @click="death">销毁vc的组件实例</button>
    </div>
</template>
<script>
export default {
    name:'Student',
    data(){
        return {
            name:'徐方君',
            age:29
        }
    },
    methods: {
        sendNameToApp(){
            this.$emit('receiveData',this.name,100,200,300,400)//这边可以传输多个参数
        },
        sendNameToApp2(){
            this.$emit('receiveData2')
        },
        unbind(){
            //解绑单个自定义事件
            // this.$off('receiveData')
            // this.$off(['receiveData','receiveData2'])//解绑多个自定义事件
            this.$off()//解绑所有自定义事件
        },
        death() {
            //组件实例对象在销毁后 会连带销毁所有的自定义事件
            this.$destroy() 
        },
    },
    
}
</script>
<style scoped>
    .demo{
        background-color: green;
    }
</style>